package threadPool;

import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.TimeUnit;

public class ThreadPoolTest {

	public static void main(String[] args){
		ExecutorService service=Executors.newFixedThreadPool(3);
		//ExecutorService service=Executors.newCachedThreadPool();
		//ExecutorService service=Executors.newSingleThreadExecutor();
		for(int i=0;i<10;i++){
			final int  task=i;
			Runnable runnable=new Runnable() {
				
				public void run() {
					// TODO Auto-generated method stub
					String name=Thread.currentThread().getName();
					for(int j=0;j<10;j++){
						System.out.println(name+" is "+j+ " in loop of  task "+task);
					}
					/*try {
						Thread.sleep(500);
					} catch (InterruptedException e) {
						// TODO Auto-generated catch block
						e.printStackTrace();
					}*/
				}
			};
			service.execute(runnable);
		}
		service.shutdown();
		//service.shutdownNow();
		
		
		//s
		ScheduledExecutorService service2=Executors.newScheduledThreadPool(3);
		service2.schedule(new Runnable() {
			
			public void run() {
				// TODO Auto-generated method stub
				System.out.println("Bombing~~~");
			}
		}, 2, TimeUnit.SECONDS);
		
		service2.shutdown();
	}
}
